package avicit.im.lantop.userauthset.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import avicit.cbb.businessclass.system.dataauth.domain.CbbAuthResource;
import avicit.cbb.businessclass.system.dataauth.service.BaseExtendAuthService;
import avicit.cbb.funcoperationset.service.FuncOperationSetIntfsService;
import avicit.im.lantop.userauthset.domain.LantopOperateClass;
import avicit.im.lantop.userauthset.domain.LantopOperateClassItem;
import avicit.im.lantop.userauthset.domain.LantopQualificationDetail;
import avicit.im.lantop.userauthset.domain.LantopUserAuthCondition;
import avicit.im.lantop.userauthset.domain.LantopUserAuthExtendData;
import avicit.im.lantop.userauthset.domain.LantopUserAuthSetExtend;
import avicit.im.lantop.userauthset.service.UserAuthService;
import avicit.platform6.commons.utils.ComUtil;
import avicit.platform6.commons.utils.PojoUtil;
import avicit.platform6.commons.utils.web.TreeNode;
import avicit.platform6.core.domain.BeanBase;
import avicit.platform6.core.exception.DaoException;
import avicit.platform6.core.jdbc.JdbcAvicit;
import avicit.platform6.core.jdbc.Page;
import avicit.platform6.core.properties.PlatformConstant.OpResult;
import avicit.platform6.core.properties.PlatformConstant.OpType;
import avicit.platform6.core.service.ServiceBase;
import avicit.platform6.modules.system.syslog.service.LogBaseFactory;
import avicit.platform6.modules.system.syslog.service.SysLogUtil;

/**
 * <p>
 * 金航数码科技有限责任公司
 * </p>
 * <p>
 * 作者：张坚
 * </p>
 * <p>
 * 邮箱：18629436468@163.com
 * </p>
 * <p>
 * 创建时间： 2014-11-24 下午2:02:52
 * </p>
 * <p>
 * 类说明：用户权限设置service类
 * <p>
 * 修改记录：
 * </p>
 */
@Service
@SuppressWarnings("unchecked")
public class UserAuthServiceImpl extends ServiceBase implements UserAuthService {

	@Autowired
	private JdbcAvicit jdbcAvicit;

	@Resource(name = "BaseAuthService")
	private BaseExtendAuthService baseExtendAuthService; // CBB项目服务实现类

	@Autowired(required = false)
	private FuncOperationSetIntfsService funcOperationSetIntfsService;

	@Override
	public void delete(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void insert(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(BeanBase arg0) throws DaoException {
		// TODO Auto-generated method stub

	}

	@Override
	public List<TreeNode> getMenuTreeNode(String orgIdentity, String orgId, String sysId, String id, String operateClassId) throws Exception {
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		// 查询业务数据
		List<Map<String, Object>> childTreeList = this.getMenuByParentId(orgIdentity, orgId, sysId, id, operateClassId);
		for (Map<String, Object> row : childTreeList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("menu_name");
			String pId = (String) row.get("PARENT_ID");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			if (null != pId && !"".equals(pId) && "-1".equals(pId)) {
				node.setIconCls("icon-im-newnrootnode");
			} else if (childCount2.longValue() > 0) {
				node.setIconCls("icon-im-newnmodulefile");
			} else {
				node.setIconCls("icon-im-newfile");
			}
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnode = getMenuTreeNode(orgIdentity, orgId, sysId, rid, operateClassId);
				node.getChildren().addAll(cnode);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodes.add(node);
		}
		return nodes;

	}

	@Override
	public List<Map<String, Object>> getMenuByParentId(String orgIdentity, String orgId, String sysId, String parentId, String operateClassId) throws Exception {
		Assert.notNull(parentId, "参数不能为空！");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("WITH SM AS ");
		sbSql.append(" (SELECT SM.CODE, SMT.NAME AS MENU_NAME, SM.ID, SM.PARENT_ID,SM.ORDER_BY ");
		sbSql.append("    FROM SYS_MENU SM ");
		sbSql.append("   INNER JOIN SYS_MENU_TL SMT ");
		sbSql.append("      ON SM.ID = SMT.SYS_MENU_ID ");
		sbSql.append("   WHERE SMT.NAME NOT IN ('系统管理', '门户小页', '系统首页', '个人事务') ");
		sbSql.append("     AND SMT.SYS_LANGUAGE_CODE = 'zh_CN' AND STATUS = '1'AND SM.ORG_IDENTITY='" + orgIdentity + "' ), "); // 只显示启用的菜单
		sbSql.append("LOC AS ");
		sbSql.append(" (SELECT LOCI.ID, LOCI.FUNC_MENU_ID, LOCI.OPERATE_CODE ");
		sbSql.append("    FROM LANTOP_OPERATE_CLASS_ITEM LOCI ");
		sbSql.append("   WHERE LOCI.LANTOP_OPERATE_CLASS_ID = ? ");
		sbSql.append("     AND LOCI.SYS_ID = ? ");
		sbSql.append("     AND LOCI.ORG_ID = ?), ");
		sbSql.append("A AS ( ");
		sbSql.append("SELECT SM.CODE AS MCODE, SM.MENU_NAME, SM.ID, SM.PARENT_ID, 'N' AS IS_OPERATE_BTN, 'N' AS IS_CONTROL,SM.ORDER_BY ");
		sbSql.append("  FROM SM ");
		sbSql.append("UNION ALL ");
		sbSql.append("SELECT CFOS.FUNC_OPERATION_CODE AS MCODE, ");
		sbSql.append("       CFOS.FUNC_OPERATION_NAME AS MENU_NAME, ");
		sbSql.append("       CFOS.ID, ");
		sbSql.append("       CFOS.FUNC_MENU_ID AS PARENT_ID, ");
		sbSql.append("       'Y' AS IS_OPERATE_BTN, ");
		sbSql.append("       CASE ");
		sbSql.append("         WHEN (SELECT COUNT(LOC.ID) ");
		sbSql.append("                 FROM LOC ");
		sbSql.append("                WHERE LOC.FUNC_MENU_ID = CFOS.FUNC_MENU_ID ");
		sbSql.append("                  AND LOC.OPERATE_CODE = CFOS.FUNC_OPERATION_CODE) > 0 THEN ");
		sbSql.append("          'Y' ");
		sbSql.append("         ELSE ");
		sbSql.append("          'N' ");
		sbSql.append("       END AS IS_CONTROL,99999 AS ORDER_BY ");
		sbSql.append("  FROM CBB_FUNC_OPERATION_SET CFOS) ");
		sbSql.append("  SELECT (SELECT COUNT(*) FROM A A2 WHERE A2.PARENT_ID = A1.ID) CHILD_COUNT, A1.* ");
		sbSql.append("  FROM A A1 ");
		sbSql.append(" WHERE A1.PARENT_ID = ? AND INSTR(A1.MCODE, 'CMS_Root') = 0 ORDER BY ORDER_BY ");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString(), new Object[] {operateClassId, sysId, orgId, parentId});
		return list;

	}

	@Override
	public List<Map<String, Object>> getResource(Map<String, Object> parameter) throws Exception {
		String targetId = (String) parameter.get("targetId");
		String sysId = (String) parameter.get("sysId");
		String orgId = (String) parameter.get("orgId");
		String menuId = (String) parameter.get("menuId");
		List<Map<String, Object>> list = this.funcOperationSetIntfsService.getFuncOperationSetInfoByIntfs(orgId, "", sysId, menuId);
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = list.get(i);
			String operateAuth = this.baseExtendAuthService.getResourceOperateAuth(orgId, sysId, targetId, "LANTOP_AUTH_SERVER_FUNC", menuId, (String) map.get("FUNC_OPERATION_CODE")); // 获取操作权限
			map.put("OPERATE_AUTH", operateAuth);
		}
		return list;
	}

	@Override
	public void saveResourceConfig(List<CbbAuthResource> cbbAuthResources, Map<String, Object> parameter) throws Exception {
		String delCbbAuthResourcesIds = (String) parameter.get("delCbbAuthResourcesIds");
		if (null != delCbbAuthResourcesIds && !"".equals(delCbbAuthResourcesIds)) {
			String[] delIds = delCbbAuthResourcesIds.split(",");
			List<String> delIdList = Arrays.asList(delIds);
			// 分批次删除,防止字符串超长无法执行sql
			int s = delIdList.size() / 30;
			int y = delIdList.size() % 30;
			if (y != 0) {
				s = s + 1;
			}
			for (int i = 0; i < s; i++) {
				String delIdString = "";
				int start = i * 30;
				int end = i * 30 + 30;
				if (i == s - 1 && delIdList.size() - i * 30 < 30) {
					end = delIdList.size();
				}
				for (int j = start; j < end; j++) {
					delIdString += "'" + delIdList.get(j) + "'";
					if (j != end - 1) {
						delIdString += ",";
					}
				}
				this.baseExtendAuthService.delCbbAuthResourceById(delIdString);
				// 删除关联权限资源授权信息的操作权限
				this.delLantopUserAuthSetExtendByResourceId(delIdString);
			}
			// delCbbAuthResourcesIds = "'" + delCbbAuthResourcesIds.replace(",", "','") + "'";
			// 删除已取消授权的权限资源信息
			// this.baseExtendAuthService.delCbbAuthResourceById(delCbbAuthResourcesIds);
			// 删除关联权限资源授权信息的操作权限
			// this.delLantopUserAuthSetExtendByResourceId(delCbbAuthResourcesIds);
		}

		for (int i = 0; i < cbbAuthResources.size(); i++) {
			String id = cbbAuthResources.get(i).getId();
			if (null != id && !"".equals(id)) {
				// 已设置权限修改
				this.baseExtendAuthService.updateCbbAuthResource(cbbAuthResources.get(i));
			} else {
				// 新增加记录设置权限
				this.baseExtendAuthService.insertCbbAuthResource(cbbAuthResources.get(i));
			}
		}
	}



	@Override
	public void getRoleUser(Page<Map<String, Object>> page, String targetName,String orgIdentity) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT distinct SU.NAME, SU.ID, SDV.DEPT_NAME, R.ROLE_NAME ");
		sbSql.append("  FROM SYS_USER SU ");
		sbSql.append(" INNER JOIN SYS_USER_ROLE SUR ");
		sbSql.append("    ON SU.ID = SUR.SYS_USER_ID ");
		sbSql.append(" INNER JOIN SYS_USER_DEPT_POSITION SUDP ");
		sbSql.append("    ON SU.ID = SUDP.USER_ID ");
		sbSql.append(" INNER JOIN SYS_DEPT_V SDV ");
		sbSql.append("    ON SDV.ID = SUDP.DEPT_ID ");
		sbSql.append(" INNER JOIN SYS_ROLE R ");
		sbSql.append(" 	  ON R.ID = SUR.SYS_ROLE_ID");
		sbSql.append(" WHERE R.ROLE_NAME = '");
		sbSql.append(targetName);
		sbSql.append("'");
		sbSql.append(" AND SUDP.ORG_IDENTITY = '"+orgIdentity+"'");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void getUser(Page<Map<String, Object>> page, String targetId,String orgIdentity) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT SU.ID, ");
		sbSql.append("       SU.NAME, ");
		sbSql.append("       SDV.DEPT_NAME, ");
		sbSql.append("       (SELECT CONCAT_CLOB_F(SR.ROLE_NAME) ");
		sbSql.append("          FROM SYS_ROLE SR ");
		sbSql.append("         WHERE SR.ID IN (SELECT SUR.SYS_ROLE_ID ");
		sbSql.append("                           FROM SYS_USER_ROLE SUR ");
		sbSql.append("                          WHERE SU.ID = SUR.SYS_USER_ID)) ROLE_NAME ");
		sbSql.append("  FROM SYS_USER SU ");
		sbSql.append(" INNER JOIN SYS_USER_DEPT_POSITION SUDP ");
		sbSql.append("    ON SU.ID = SUDP.USER_ID ");
		sbSql.append(" INNER JOIN SYS_DEPT_V SDV ");
		sbSql.append("    ON SDV.ID = SUDP.DEPT_ID ");
		sbSql.append(" WHERE SU.ID = '");
		sbSql.append(targetId);
		sbSql.append("' AND SUDP.ORG_IDENTITY = '"+orgIdentity+"'");
		sbSql.append(" ORDER BY SU.NAME");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void getDetpUser(Page<Map<String, Object>> page, String targetId,String orgIdentity) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT SU.ID, ");
		sbSql.append("       SU.NAME, ");
		sbSql.append("       SDV.DEPT_NAME, ");
		sbSql.append("       (SELECT CONCAT_CLOB_F(SR.ROLE_NAME) ");
		sbSql.append("          FROM SYS_ROLE SR ");
		sbSql.append("         WHERE SR.ID IN (SELECT SUR.SYS_ROLE_ID ");
		sbSql.append("                           FROM SYS_USER_ROLE SUR ");
		sbSql.append("                          WHERE SU.ID = SUR.SYS_USER_ID)) ROLE_NAME ");
		sbSql.append("  FROM SYS_USER SU ");
		sbSql.append(" INNER JOIN SYS_USER_DEPT_POSITION SUDP ");
		sbSql.append("    ON SU.ID = SUDP.USER_ID ");
		sbSql.append(" INNER JOIN SYS_DEPT_V SDV ");
		sbSql.append("    ON SDV.ID = SUDP.DEPT_ID ");
		sbSql.append(" WHERE SUDP.DEPT_ID = '");
		sbSql.append(targetId);
		sbSql.append("' AND SUDP.ORG_IDENTITY = '"+orgIdentity+"'");
		sbSql.append(" ORDER BY SU.NAME");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void getGroupUser(Page<Map<String, Object>> page, String targetId,String orgIdentity) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT SU.ID, ");
		sbSql.append("       SU.NAME, ");
		sbSql.append("       SDV.DEPT_NAME, ");
		sbSql.append("       (SELECT CONCAT_CLOB_F(SR.ROLE_NAME) ");
		sbSql.append("          FROM SYS_ROLE SR ");
		sbSql.append("         WHERE SR.ID IN (SELECT SUR.SYS_ROLE_ID ");
		sbSql.append("                           FROM SYS_USER_ROLE SUR ");
		sbSql.append("                          WHERE SU.ID = SUR.SYS_USER_ID)) ROLE_NAME ");
		sbSql.append("  FROM SYS_USER SU ");
		sbSql.append(" INNER JOIN SYS_USER_DEPT_POSITION SUDP ");
		sbSql.append("    ON SU.ID = SUDP.USER_ID ");
		sbSql.append(" INNER JOIN SYS_DEPT_V SDV ");
		sbSql.append("    ON SDV.ID = SUDP.DEPT_ID ");
		sbSql.append(" INNER JOIN SYS_USER_GROUP SUG ");
		sbSql.append("    ON SUG.USER_ID = SU.ID ");
		sbSql.append(" WHERE SUG.GROUP_ID = '");
		sbSql.append(targetId);
		sbSql.append("' AND SUDP.ORG_IDENTITY = '"+orgIdentity+"'");
		sbSql.append(" ORDER BY SU.NAME");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void getPositionUser(Page<Map<String, Object>> page, String targetId,String orgIdentity) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT SU.ID, ");
		sbSql.append("       SU.NAME, ");
		sbSql.append("       SDV.DEPT_NAME, ");
		sbSql.append("       (SELECT CONCAT_CLOB_F(SR.ROLE_NAME) ");
		sbSql.append("          FROM SYS_ROLE SR ");
		sbSql.append("         WHERE SR.ID IN (SELECT SUR.SYS_ROLE_ID ");
		sbSql.append("                           FROM SYS_USER_ROLE SUR ");
		sbSql.append("                          WHERE SU.ID = SUR.SYS_USER_ID)) ROLE_NAME ");
		sbSql.append("  FROM SYS_USER SU ");
		sbSql.append(" INNER JOIN SYS_USER_DEPT_POSITION SUDP ");
		sbSql.append("    ON SU.ID = SUDP.USER_ID ");
		sbSql.append(" INNER JOIN SYS_DEPT_V SDV ");
		sbSql.append("    ON SDV.ID = SUDP.DEPT_ID ");
		sbSql.append(" INNER JOIN SYS_POSITION SP ");
		sbSql.append("    ON SUDP.POSITION_ID = SP.ID ");
		sbSql.append(" INNER JOIN SYS_POSITION_TL SPT ");
		sbSql.append("    ON SP.ID = SPT.SYS_POSITION_ID ");
		sbSql.append("   AND SPT.SYS_LANGUAGE_CODE = 'zh_CN' ");
		sbSql.append(" WHERE SP.ID = '");
		sbSql.append(targetId);
		sbSql.append("' AND SUDP.ORG_IDENTITY = '"+orgIdentity+"'");
		sbSql.append(" ORDER BY SU.NAME");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public List<Map<String, Object>> getArchiveClass(Map<String, Object> param) {
		StringBuffer sbSql = new StringBuffer();
		String targetType = (String) param.get("targetType");
		String targetId = (String) param.get("targetId");
		String orgId = (String) param.get("orgId");
		String sysId = (String) param.get("sysId");
		int userAuthColSize = Integer.parseInt(param.get("userAuthColSize") + "");
		int beginIndex = 1;

		sbSql.append("WITH CARU AS ");
		sbSql.append(" (SELECT distinct(CART.ID), ");
		sbSql.append("         CART.AUTH_SERVICE_ID, ");
		sbSql.append("         CART.TARGET_TYPE, ");
		sbSql.append("         CART.TARGET_ID, ");
		sbSql.append("         CART.CODE, ");
		sbSql.append("         CART.NAME, ");
		sbSql.append("         CART.ACTION_TYPE, ");
		sbSql.append("         CART.OPERATE_AUTH, ");
		// sbSql.append("         SUBSTR(CART.OPERATE_AUTH, 1, 1) AS A1, ");
		// //条目浏览
		// sbSql.append("         SUBSTR(CART.OPERATE_AUTH, 3, 1) AS A2, ");
		// //全文浏览
		// sbSql.append("         SUBSTR(CART.OPERATE_AUTH, 5, 1) AS A3, ");
		// //全文打印
		// sbSql.append("         SUBSTR(CART.OPERATE_AUTH, 7, 1) AS A4, ");
		// //全文下载
		for (int i = 1; i <= userAuthColSize; i++) {
			// 权限类型查询根据注册的权限类型条目动态生成查询sql，上面是固定写法规则，这种写法目前最多支持9种权限
			sbSql.append("         SUBSTR(CART.OPERATE_AUTH, ");
			sbSql.append(beginIndex);
			sbSql.append(", 1) AS A");
			sbSql.append(i);
			sbSql.append(", ");
			beginIndex = beginIndex + 2;
		}
		sbSql.append("         LUASE.REL_TARGET_ID, ");
		sbSql.append("         LUASE.REL_TARGET_NAME ");
		sbSql.append("    FROM CBB_AUTH_RESOURCE CART ");
		sbSql.append("    LEFT JOIN LANTOP_USER_AUTH_SET_EXTEND LUASE ");
		sbSql.append("      ON CART.ID = LUASE.CBB_AUTH_RESOURCE_ID ");
		sbSql.append("   WHERE CART.TARGET_TYPE = '" + targetType + "' ");
		sbSql.append("     AND CART.ORG_ID = '" + orgId + "'");
		sbSql.append("     AND CART.SYS_ID = '" + sysId + "'");
		sbSql.append("     AND CART.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_USERSET' ");
		sbSql.append("     AND CART.TARGET_ID = '" + targetId + "'");
		sbSql.append("   ) ");
		sbSql.append("SELECT LAC.ORG_ID, ");
		sbSql.append("       LAC.DEPT_ID, ");
		sbSql.append("       LAC.SYS_ID, ");
		sbSql.append("       LAC.ARCHIVE_CLASS_NODE_NAME, ");
		sbSql.append("       LAC.ARCHIVE_CLASS_NODE_TYPE, ");
		sbSql.append("       LAC.ID, ");
		sbSql.append("       LAC.PARENT_ID, ");
		sbSql.append("       CARU.ID                     AS CBB_AUTH_RESOURCE_ID,");
		sbSql.append("       CARU.AUTH_SERVICE_ID, ");
		sbSql.append("       CARU.TARGET_TYPE, ");
		sbSql.append("       CARU.TARGET_ID, ");
		sbSql.append("       CARU.CODE                   AS RES_CODE, ");
		sbSql.append("       CARU.NAME                   AS RES_NAME, ");
		sbSql.append("       CARU.ACTION_TYPE, ");
		sbSql.append("       CARU.OPERATE_AUTH, ");
		sbSql.append("       LAC.ARCHIVE_TYPE,");
		// 这里用来在jsp页面绘制复选框时区分动态列,0为默认未选中
		// sbSql.append("       CASE ");
		// sbSql.append("        WHEN CARU.A1 IS NULL THEN 'A10' ");
		// sbSql.append("        ELSE 'A1' || CARU.A1 ");
		// sbSql.append("       END A1, ");
		// 动态拼接数据权限对应的值，对应上面的动态sql操作：上面是固定写法规则，这种写法目前最多支持9种权限
		// 这里在列查询出的值前面加上列名，是为了在jsp动态生成复选框方法时区分不同的列
		for (int i = 1; i <= userAuthColSize; i++) {
			sbSql.append("       CASE ");
			sbSql.append("        WHEN CARU.A");
			sbSql.append(i);
			sbSql.append(" IS NULL THEN 'A");
			sbSql.append(i);
			sbSql.append("0' ");
			sbSql.append("        ELSE 'A");
			sbSql.append(i);
			sbSql.append("' || CARU.A");
			sbSql.append(i);
			sbSql.append("       END A");
			sbSql.append(i);
			sbSql.append(", ");
		}
		// end
		sbSql.append("       CARU.REL_TARGET_ID, ");
		sbSql.append("       CARU.REL_TARGET_NAME, ");
		sbSql.append("       (SELECT COUNT(C.DATA_AUTH) FROM CBB_AUTH_RESOURCE C WHERE C.DATA_AUTH IS NOT NULL AND C.TARGET_TYPE = '" + targetType + "' AND C.TARGET_ID = '" + targetId + "' AND C.ORG_ID = '" + orgId + "' AND C.SYS_ID = '" + sysId
				+ "' AND INSTR(C.CODE, LAC.ID) > 0) AS DATA_AUTH ");
		sbSql.append("  FROM LANTOP_ARCHIVE_CLASS LAC ");
		sbSql.append("  LEFT JOIN CARU ");
		sbSql.append("    ON LAC.ID = CARU.CODE ");
		sbSql.append(" WHERE LAC.ORG_ID = '");
		sbSql.append(orgId);
		sbSql.append("' ");
		sbSql.append("   AND LAC.SYS_ID = '");
		sbSql.append(sysId);
		sbSql.append("' ");
		sbSql.append(" AND LAC.ARCHIVE_CLASS_NODE_CODE NOT IN ('BMWJ','GRWJ') AND LAC.ID NOT IN ");
		sbSql.append("(SELECT T.ID ");
		sbSql.append("  FROM LANTOP_ARCHIVE_CLASS T ");
		sbSql.append(" WHERE T.ARCHIVE_TYPE = '10') ");
		//sbSql.append(" CONNECT BY PRIOR T.PARENT_ID = T.ID AND PARENT_ID != 'ROOT')");
		sbSql.append(" ORDER BY LAC.NODE_SORT_NUMBER,LAC.CREATION_DATE");
		List<Map<String, Object>> list = this.jdbcAvicit.queryForMap(sbSql.toString(), null);
		return list;
	}

	@Override
	public void getAlreadySetRoles(avicit.platform6.core.jdbc.Page<Map<String, Object>> page, String relTargetId) {

	}

	@Override
	public void getRoleSetOperate(avicit.platform6.core.jdbc.Page<Map<String, Object>> page, Map<String, Object> param) {

	}

	@Override
	public void getNoSetRoles(avicit.platform6.core.jdbc.Page<Map<String, Object>> page, Map<String, Object> param) {

	}

	@Override
	public void getAlreadySetRoles(Page<Map<String, Object>> page, String relTargetId) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT SR.ID, SR.ROLE_NAME, SR.ROLE_DESC ");
		sbSql.append("  FROM SYS_ROLE SR ");
		sbSql.append(" WHERE INSTR('");
		sbSql.append(relTargetId);
		sbSql.append("', SR.ID) > 0");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void getRoleSetOperate(Page<Map<String, Object>> page, Map<String, Object> param) {
		StringBuffer sbSql = new StringBuffer();
		String targetId = (String) param.get("targetId"); // 所选角色ID
		String sysId = (String) param.get("sysId"); // 系统标识ID
		String orgId = (String) param.get("orgId"); // 组织ID

		sbSql.append("SELECT SR.ROLE_NAME, ");
		sbSql.append("       CFOS.FUNC_MENU_NAME, ");
		sbSql.append("       CFOS.FUNC_OPERATION_CODE, ");
		sbSql.append("       CFOS.FUNC_OPERATION_NAME, ");
		sbSql.append("       CAR.OPERATE_AUTH ");
		sbSql.append("  FROM CBB_FUNC_OPERATION_SET CFOS ");
		sbSql.append(" INNER JOIN CBB_AUTH_RESOURCE CAR ");
		sbSql.append("    ON CFOS.FUNC_MENU_ID = CAR.CODE ");
		sbSql.append("   AND CFOS.FUNC_OPERATION_CODE = CAR.ACTION_TYPE ");
		sbSql.append(" INNER JOIN SYS_ROLE SR ");
		sbSql.append("    ON SR.ID = CAR.TARGET_ID ");
		sbSql.append(" WHERE CAR.SYS_ID = '" + sysId + "'");
		sbSql.append("  AND CAR.ORG_ID = '" + orgId + "'");
		sbSql.append("  AND CAR.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_FUNC'");
		sbSql.append("  AND CAR.TARGET_TYPE = '1' ");
		sbSql.append("  AND CAR.TARGET_ID = '" + targetId + "'");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void getNoSetRoles(Page<Map<String, Object>> page, Map<String, Object> param) {
		String sysId = (String) param.get("sysId");
		String orgId = (String) param.get("orgId");
		String targetId = (String) param.get("targetId");
		String code = (String) param.get("code");

		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT SR.ID, SR.ROLE_CODE, SR.ROLE_NAME, SR.ROLE_DESC ");
		sbSql.append("  FROM SYS_ROLE SR ");
		sbSql.append(" WHERE SR.VALID_FLAG = '1' ");
		sbSql.append("   AND NOT EXISTS ");
		sbSql.append(" (SELECT 1 ");
		sbSql.append("          FROM CBB_AUTH_RESOURCE CAR ");
		sbSql.append("         INNER JOIN LANTOP_USER_AUTH_SET_EXTEND LUASE ");
		sbSql.append("            ON CAR.ID = LUASE.CBB_AUTH_RESOURCE_ID ");
		sbSql.append("         WHERE INSTR(LUASE.REL_TARGET_ID, SR.ID) > 0 ");
		sbSql.append("           AND CAR.SYS_ID = '" + sysId + "'");
		sbSql.append("           AND CAR.ORG_ID = '" + orgId + "'");
		sbSql.append("           AND CAR.TARGET_TYPE = '2' ");
		sbSql.append("           AND CAR.TARGET_ID = '" + targetId + "'");
		sbSql.append("           AND CAR.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_USERSET' ");
		sbSql.append("           AND INSTR('" + code + "', CAR.CODE) > 0) ");
		sbSql.append(" 	AND EXISTS (SELECT 2 ");
		sbSql.append("          FROM CBB_AUTH_RESOURCE CAR ");
		sbSql.append("         WHERE CAR.TARGET_TYPE = '1' ");
		sbSql.append("           AND CAR.SYS_ID = '" + sysId + "'");
		sbSql.append("           AND CAR.ORG_ID = '" + orgId + "'");
		sbSql.append("           AND CAR.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_FUNC'");
		sbSql.append("           AND CAR.TARGET_ID = SR.ID)");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public LantopUserAuthSetExtend getLantopUserAuthSetExtend(String cbbAuthResourceId) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("from LantopUserAuthSetExtend where cbbAuthResourceId = '");
		sbSql.append(cbbAuthResourceId);
		sbSql.append("'");

		List<LantopUserAuthSetExtend> lantopUserAuthSetExtends = this.hibernateDao.find(sbSql.toString());
		if (null != lantopUserAuthSetExtends && lantopUserAuthSetExtends.size() > 0) {
			return lantopUserAuthSetExtends.get(0);
		}
		return null;
	}

	@Override
	public void insertLantopUserAuthSetExtend(LantopUserAuthSetExtend lantopUserAuthSetExtend) throws Exception {
		lantopUserAuthSetExtend.setId(ComUtil.getId());
		PojoUtil.setSysProperties(lantopUserAuthSetExtend, OpType.insert);
		hibernateDao.save(lantopUserAuthSetExtend);
		SysLogUtil.log(lantopUserAuthSetExtend, null, OpType.insert, OpResult.success);
	}

	@Override
	public void delLantopUserAuthSetExtend(String id) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM LANTOP_USER_AUTH_SET_EXTEND T WHERE T.ID = '" + id + "'");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	@Override
	public void delRoleSet(LantopUserAuthSetExtend lantopUserAuthSetExtend, String delTargetIds, String delTargetNames) throws Exception {
		String[] delTargetId = delTargetIds.split(","); // 要删除的角色ID串
		String[] delTargetName = delTargetNames.split(","); // 要删除的角色名称串
		// 在已设置角色ID串末尾加上逗号，然后通过ID+逗号方式替换掉所有要删除的ID，在更新原有记录
		String relTargetId = lantopUserAuthSetExtend.getRelTargetId() + ",";
		String relTargetName = lantopUserAuthSetExtend.getRelTargetName() + ",";
		for (int i = 0; i < delTargetId.length; i++) {
			relTargetId = relTargetId.replace(delTargetId[i] + ",", "");
			relTargetName = relTargetName.replace(delTargetName[i] + ",", "");
		}
		if (relTargetId.lastIndexOf(",") == relTargetId.length() - 1) {
			relTargetId = relTargetId.substring(0, relTargetId.length() - 1);
		}
		if (relTargetName.lastIndexOf(",") == relTargetName.length() - 1) {
			relTargetName = relTargetName.substring(0, relTargetName.length() - 1);
		}
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("UPDATE LANTOP_USER_AUTH_SET_EXTEND SET REL_TARGET_ID = '" + relTargetId + "'");
		sbSql.append(", REL_TARGET_NAME = '" + relTargetName + "'");
		sbSql.append(" WHERE ID = '" + lantopUserAuthSetExtend.getId() + "'");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "修改权限设置记录", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
	}







	@Override
	public void getElectronicWaitSelectEntry(Page<Map<String, Object>> page, Map<String, Object> param) {
		List<Map<String, Object>> tableList = (ArrayList<Map<String, Object>>) param.get("tableList");
		String orgId = (String) param.get("orgId");
		String sysId = (String) param.get("sysId");
		String nodeIds = (String) param.get("nodeIds");
		String targetType = (String) param.get("targetType");
		String targetId = (String) param.get("targetId");
		Map<String, Object> searchMap = (HashMap<String, Object>) param.get("searchMap"); // 查询参数
		// 根据查询参数拼接查询条件
		StringBuffer searchSqlSb = new StringBuffer();
		String attachName = (String) searchMap.get("ATTACH_NAME");
		if (null != attachName && !"".equals(attachName)) {
			searchSqlSb.append(" AND SA.ATTACH_NAME LIKE '%");
			searchSqlSb.append(attachName);
			searchSqlSb.append("%' ");
		}
		StringBuffer sbSql = new StringBuffer();
		for (int i = 0; i < tableList.size(); i++) {
			if (i != 0) {
				sbSql.append("UNION ALL ");
			}
			sbSql.append("SELECT LAC.ARCHIVE_CLASS_NODE_NAME, LAC.ID AS ARCHIVE_CLASS_ID, SA.ID, SA.ATTACH_NAME, SA.ATTACH_TYPE, '");
			sbSql.append(tableList.get(i).get("ID")); // 物理表ID
			sbSql.append("' AS TABLE_ID,T.WJH,T.TM   FROM ");
			sbSql.append(tableList.get(i).get("TABLE_NAME")); // 物理表名
			sbSql.append(" T  INNER JOIN LANTOP_ARCHIVE_CLASS LAC ");
			sbSql.append("    ON T.NODE_ID = LAC.ID ");
			sbSql.append(" LEFT JOIN CBB_DOC_RELATION CDR ");
			sbSql.append("    ON T.ID = CDR.RECORD_ID ");
			sbSql.append(" LEFT JOIN SYS_ATTACHMENT SA ");
			sbSql.append("    ON CDR.ATTACHMENT_ID = SA.ID ");
			sbSql.append(" WHERE T.ORG_ID = '" + orgId + "'");
			sbSql.append(" AND T.SYS_ID = '" + sysId + "'");
			sbSql.append(" AND T.NODE_ID IN (" + nodeIds + ")");
			sbSql.append(" AND CDR.IF_DELETE = 'N'"); // 20160818 wangzp
														// update
			sbSql.append(" AND T.ARCHIVE_STATUS NOT IN ('2') ");// 修改 去掉已删除和未归档的
			sbSql.append(" AND NOT EXISTS ");
			sbSql.append(" (SELECT 1 ");
			sbSql.append("          FROM LANTOP_USER_AUTH_EXTEND_DATA LUAED ");
			sbSql.append("         WHERE LUAED.TARGET_TYPE = '" + targetType + "' ");
			sbSql.append("           AND LUAED.TARGET_ID = '");
			sbSql.append(targetId);
			sbSql.append("'          AND LUAED.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_USERSET' ");
			sbSql.append("           AND LUAED.RES_CODE = SA.ID) ");
		}
		sbSql.append(searchSqlSb);
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void getNotElectronicWaitSelectEntry(Page<Map<String, Object>> page, Map<String, Object> param) {
		String tableName = (String) param.get("tableName"); // 物理表名
		String tableId = (String) param.get("tableId"); // 物理表ID
		String orgId = (String) param.get("orgId");
		String sysId = (String) param.get("sysId");
		String nodeIds = (String) param.get("nodeIds");
		String targetType = (String) param.get("targetType");
		String targetId = (String) param.get("targetId");
		Map<String, Object> searchMap = (HashMap<String, Object>) param.get("searchMap"); // 查询参数
		// 根据查询参数拼接查询条件
		StringBuffer searchSqlSb = new StringBuffer();
		String wjh = (String) searchMap.get("WJH");
		String tm = (String) searchMap.get("TM");
		if (null != wjh && !"".equals(wjh)) {
			searchSqlSb.append(" AND T.WJH LIKE '%");
			searchSqlSb.append(wjh);
			searchSqlSb.append("%' ");
		}
		if (null != tm && !"".equals(tm)) {
			searchSqlSb.append(" AND T.TM LIKE '%");
			searchSqlSb.append(tm);
			searchSqlSb.append("%' ");
		}

		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT LAC.ARCHIVE_CLASS_NODE_NAME, LAC.ID AS ARCHIVE_CLASS_ID, T.ID, T.WJH AS WJH, T.TM AS TM, '");
		sbSql.append(tableId);
		sbSql.append("' AS TABLE_ID   FROM ");
		sbSql.append(tableName);
		sbSql.append(" T INNER JOIN LANTOP_ARCHIVE_CLASS LAC ");
		sbSql.append("    ON T.NODE_ID = LAC.ID ");
		sbSql.append(" WHERE T.ORG_ID = '");
		sbSql.append(orgId);
		sbSql.append("'  AND T.SYS_ID = '");
		sbSql.append(sysId);
		sbSql.append("'  AND T.ARCHIVE_STATUS NOT IN ('2') ");// 修改 去掉已删除和未归档的
		sbSql.append("  AND T.NODE_ID IN (");
		sbSql.append(nodeIds);
		sbSql.append(")   AND NOT EXISTS ");
		sbSql.append(" (SELECT 1 ");
		sbSql.append("          FROM LANTOP_USER_AUTH_EXTEND_DATA LUAED ");
		sbSql.append("         WHERE LUAED.TARGET_TYPE = '" + targetType + "' ");
		sbSql.append("           AND LUAED.TARGET_ID = '");
		sbSql.append(targetId);
		sbSql.append("'          AND LUAED.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_USERSET' ");
		sbSql.append("           AND LUAED.RES_CODE = T.ID)");
		sbSql.append(searchSqlSb);
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void getAuthEntry(Page<Map<String, Object>> page, Map<String, Object> param) {

		String orgId = (String) param.get("orgId");
		String sysId = (String) param.get("sysId");
		String targetId = (String) param.get("targetId");
		String targetType = (String) param.get("targetType");
		String nodeIds = (String) param.get("nodeIds");
		int userAuthColSize = Integer.parseInt(param.get("userAuthColSize") + "");
		int beginIndex = 1;

		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT   LAC.ARCHIVE_CLASS_NODE_NAME, ");
		sbSql.append("          LUAED.ID, ");
		sbSql.append("       LUAED.TARGET_TYPE, ");
		sbSql.append("       LUAED.TARGET_ID, ");
		sbSql.append("       LUAED.AUTH_SERVICE_ID, ");
		sbSql.append("       LUAED.RCD_DATA_TYPE, ");
		sbSql.append("       LUAED.ARCHIVE_CLASS_ID, ");
		sbSql.append("       LUAED.ARCHIVE_TABLE_ID AS TABLE_ID, ");
		sbSql.append("       LUAED.DATA_AUTH, ");
		sbSql.append("       LUAED.DATA_AUTH_SHOW, ");
		sbSql.append("       LUAED.START_DATE, ");
		sbSql.append("       LUAED.END_DATE, ");
		sbSql.append("       LUAED.RES_CODE, ");
		sbSql.append("       LUAED.RES_NAME, ");
		sbSql.append("       LUAED.WJH, ");
		sbSql.append("       LUAED.TM, ");
		sbSql.append("       LUAED.ATTRIBUTE_01 AS ATTACH_NAME, "); // 电子文件名称
		sbSql.append("       LUAED.ACTION_TYPE, ");
		sbSql.append("       LUAED.OPERATE_AUTH, ");
		for (int i = 1; i <= userAuthColSize; i++) {
			// 权限类型查询根据注册的权限类型条目动态生成查询sql，上面是固定写法规则，这种写法目前最多支持9种权限
			sbSql.append(" 'A");
			sbSql.append(i);
			sbSql.append("' ||       SUBSTR(LUAED.OPERATE_AUTH, ");
			sbSql.append(beginIndex);
			sbSql.append(", 1) AS A");
			sbSql.append(i);
			if (i != userAuthColSize) {
				sbSql.append(", ");
			}
			beginIndex = beginIndex + 2;
		}
		sbSql.append("  FROM LANTOP_USER_AUTH_EXTEND_DATA LUAED ");
		sbSql.append(" INNER JOIN LANTOP_ARCHIVE_CLASS LAC ");
		sbSql.append("    ON LUAED.ARCHIVE_CLASS_ID = LAC.ID ");
		sbSql.append(" WHERE LUAED.ORG_ID = '");
		sbSql.append(orgId);
		sbSql.append("'  AND LUAED.SYS_ID = '");
		sbSql.append(sysId);
		sbSql.append("'  AND LUAED.TARGET_TYPE = '" + targetType + "' ");
		sbSql.append("   AND LUAED.TARGET_ID = '");
		sbSql.append(targetId);
		sbSql.append("'  AND LUAED.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_USERSET' ");
		sbSql.append("   AND LUAED.ARCHIVE_CLASS_ID IN (");
		sbSql.append(nodeIds);
		sbSql.append(")");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void saveAuthEntry(List<LantopUserAuthExtendData> lantopUserAuthExtendDatas, Map<String, Object> param) throws Exception {
		for (int i = 0; i < lantopUserAuthExtendDatas.size(); i++) {
			LantopUserAuthExtendData lantopUserAuthExtendData = lantopUserAuthExtendDatas.get(i);
			if (null != lantopUserAuthExtendData.getId() && !"".equals(lantopUserAuthExtendData.getId())) {
				// 先删除，在保存
				this.delLantopUserAuthExtendDataById(lantopUserAuthExtendData.getId());
			}
			if (lantopUserAuthExtendData.getOperateAuth().indexOf("1") >= 0) {
				// 存在权限设置，如果不不存在权限设置则不保存，已保存过的权限也将被上一个操作删除
				this.insertLantopUserAuthExtendData(lantopUserAuthExtendData);
			} else if (lantopUserAuthExtendData.getOperateAuth().indexOf("1") < 0 && null != lantopUserAuthExtendData.getId() && !"".equals(lantopUserAuthExtendData.getId())) {
				this.delLantopUserAuthExtendDataById(lantopUserAuthExtendData.getId());
			}
		}
	}

	@Override
	public void delLantopUserAuthExtendDataById(String id) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM LANTOP_USER_AUTH_EXTEND_DATA WHERE ID = '");
		sbSql.append(id);
		sbSql.append("'");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	@Override
	public void insertLantopUserAuthExtendData(LantopUserAuthExtendData lantopUserAuthExtendData) throws Exception {
		lantopUserAuthExtendData.setId(ComUtil.getId());
		PojoUtil.setSysProperties(lantopUserAuthExtendData, OpType.insert);
		hibernateDao.save(lantopUserAuthExtendData);
		SysLogUtil.log(lantopUserAuthExtendData, null, OpType.insert, OpResult.success);
	}

	@Override
	public void delAuthEntry(String ids) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM LANTOP_USER_AUTH_EXTEND_DATA WHERE ID IN (");
		sbSql.append(ids);
		sbSql.append(")");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	@Override
	public void saveQualification(Map<String, Object> param) throws Exception {
		String orgId = (String) param.get("orgId");
		String deptId = (String) param.get("deptId");
		String sysId = (String) param.get("sysId");
		String targetType = (String) param.get("targetType"); // 授权维度ID
		String targetId = (String) param.get("targetId"); // 用户ID
		String authServiceId = (String) param.get("authServiceId"); // 服务ID
		String nodeIds = (String) param.get("nodeIds"); // 父页面所选节点ID串
		String nodeNames = (String) param.get("nodeNames"); // 父页面所选节点名称串
		String tableId = (String) param.get("tableId"); // 数据表ID
		String tableName = (String) param.get("tableName");
		String authType = (String) param.get("authType"); // 权限类型
		String tableHtml = (String) param.get("tableHtml"); // 表格行内容，HTML代码
		String qualificationSql = (String) param.get("qualificationSql"); // 新增条件生成的sql
		String qualificationShowSql = (String) param.get("qualificationShowSql"); // 新增条件生成的sql语句中文描述
		String startDate = param.get("startDate") + ""; // 开始时间
		String endDate = param.get("endDate") + ""; // 结束时间

		String[] nodeId = nodeIds.split(","); // 所选ID数组
		String[] nodeName = nodeNames.split(","); // 所选节点名称数组

		// 系统将所选节点、数据表以及条目类型信息保存到CBB_AUTH_RESOURCE表中（先删除后添加，按照TARGET_TYPE、TARGET_ID、AUTH_SERVICE_ID、CODE、ACTION_TYPE组合唯一）
		for (int i = 0; i < nodeId.length; i++) {
			CbbAuthResource oldCbbAuthResource = this.baseExtendAuthService.getCbbAuthResource(orgId, sysId, targetType, targetId, authServiceId, nodeId[i] + "_" + tableId, authType);
			LantopUserAuthSetExtend oldLantopUserAuthSetExtend = null;
			if (null != oldCbbAuthResource) {
				// 根据权限资源ID获取用户权限扩展信息并删除
				oldLantopUserAuthSetExtend = this.getLantopUserAuthSetExtend(oldCbbAuthResource.getId());
				this.delLantopQualificationDetail(oldCbbAuthResource.getId()); // 删除条件权限明细信息
				this.baseExtendAuthService.deleteCbbAuthResource(orgId, sysId, targetType, targetId, authServiceId, nodeId[i] + "_" + tableId, authType);
			}
			CbbAuthResource cbbAuthResource = new CbbAuthResource();
			cbbAuthResource.setOrgId(orgId);
			cbbAuthResource.setDeptId(deptId);
			cbbAuthResource.setSysId(sysId);
			cbbAuthResource.setTargetType(targetType);
			cbbAuthResource.setTargetId(targetId);
			cbbAuthResource.setAuthServiceId(authServiceId);
			cbbAuthResource.setCode(nodeId[i] + "_" + tableId);
			cbbAuthResource.setName(nodeName[i] + "_" + tableName);
			cbbAuthResource.setActionType(authType);
			cbbAuthResource.setOperateAuth("1");
			cbbAuthResource.setDataAuth(qualificationSql);
			cbbAuthResource.setDataAuthConfig(tableHtml);
			this.baseExtendAuthService.insertCbbAuthResource(cbbAuthResource);
			param.put("cbbAuthResourceId", cbbAuthResource.getId()); // 用于保存条件明细

			if (null != oldLantopUserAuthSetExtend) {
				this.delLantopUserAuthSetExtend(oldLantopUserAuthSetExtend.getId());
			}
			// 删除后保存新记录
			LantopUserAuthSetExtend lantopUserAuthSetExtend = new LantopUserAuthSetExtend();
			lantopUserAuthSetExtend.setOrgId(orgId);
			lantopUserAuthSetExtend.setDeptId(deptId);
			lantopUserAuthSetExtend.setSysId(sysId);
			lantopUserAuthSetExtend.setCbbAuthResourceId(cbbAuthResource.getId());
			lantopUserAuthSetExtend.setTargetType(targetType);
			lantopUserAuthSetExtend.setTargetId(targetId);
			lantopUserAuthSetExtend.setAuthServiceId(authServiceId);
			lantopUserAuthSetExtend.setResCode(cbbAuthResource.getCode());
			lantopUserAuthSetExtend.setResName(cbbAuthResource.getName());
			lantopUserAuthSetExtend.setActionType(authType);
			lantopUserAuthSetExtend.setOperateAuth("1");
			lantopUserAuthSetExtend.setDataAuth(qualificationSql); // 数据权限sql
			lantopUserAuthSetExtend.setDataAuthShow(qualificationShowSql); // 数据权限sql中文显示
			lantopUserAuthSetExtend.setStartDate(ComUtil.String2Date(startDate));
			lantopUserAuthSetExtend.setEndDate(ComUtil.String2Date(endDate));
			this.insertLantopUserAuthSetExtend(lantopUserAuthSetExtend);
		}
	}

	public void insertLantopUserAuthConditions(List<LantopUserAuthCondition> luacs, Map<String, Object> param) throws Exception {
		String resourceId = (String) param.get("resourceId");
		String nodeIds = (String) param.get("nodeIds");
		String tableId = (String) param.get("tableId");
		String actionType = (String) param.get("actionType");
		String[] nodeIdArray = nodeIds.split(",");
		for (int i = 0; i < nodeIdArray.length; i++) {
			// 删除原条件记录
			String sql = "DELETE FROM LANTOP_USER_AUTH_CONDITION WHERE CODE_IDE = '" + nodeIdArray[i] + "_" + tableId + "' AND ACTION_TYPE = '" + actionType + "'";
			this.jdbcAvicit.getJdbcTemplate().execute(sql);
			// 添加新条件记录
			for (int j = 0; j < luacs.size(); j++) {
				LantopUserAuthCondition luac = luacs.get(j);
				luac.setId(ComUtil.getId());
				luac.setActionType(actionType);
				luac.setCodeIde(nodeIdArray[i] + "_" + tableId);
				luac.setResourceId(resourceId);
				PojoUtil.setSysProperties(luac, OpType.insert);
				hibernateDao.save(luac);
				SysLogUtil.log(luac, null, OpType.insert, OpResult.success);
			}
		}
	}

	@Override
	public void insertLantopOperateClass(LantopOperateClass lantopOperateClass) throws Exception {
		lantopOperateClass.setId(ComUtil.getId());
		PojoUtil.setSysProperties(lantopOperateClass, OpType.insert);
		hibernateDao.save(lantopOperateClass);
		SysLogUtil.log(lantopOperateClass, null, OpType.insert, OpResult.success);
	}

	@Override
	public void updateLantopOperateClass(LantopOperateClass lantopOperateClass) throws Exception {
		LantopOperateClass oldBean = this.hibernateDao.get(LantopOperateClass.class, lantopOperateClass.getId());
		this.hibernateDao.evict(oldBean);
		LantopOperateClass newBean = new LantopOperateClass();
		PojoUtil.copyProperties(newBean, oldBean, true);
		PojoUtil.copyProperties(newBean, lantopOperateClass, true);
		SysLogUtil.log(newBean, oldBean, OpType.update, OpResult.success);
		PojoUtil.setSysProperties(newBean, OpType.update);
		this.hibernateDao.update(newBean);
	}

	@Override
	public void delLantopOperateClass(String ids) throws Exception {
		// 删除权限分类
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM LANTOP_OPERATE_CLASS WHERE ID IN (");
		sbSql.append(ids);
		sbSql.append(")");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "删除权限分类记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		// 删除权限分类下权限设置
		StringBuffer sbSql1 = new StringBuffer();
		sbSql1.append("DELETE FROM LANTOP_OPERATE_CLASS_ITEM WHERE LANTOP_OPERATE_CLASS_ID IN (");
		sbSql1.append(ids);
		sbSql1.append(")");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql1.toString());
		SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	@Override
	public void getOperateClass(String sysId, String deptId, String orgId, avicit.platform6.core.jdbc.Page<Map<String, Object>> page, Map<String, Object> param) {

	}

	@Override
	public void getOperateClass(String sysId, String deptId, String orgId, Page<Map<String, Object>> page, Map<String, Object> param) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT * FROM LANTOP_OPERATE_CLASS T");
		sbSql.append(" WHERE T.SYS_ID = '" + sysId + "'");
		sbSql.append(" AND T.ORG_ID = '" + orgId + "'");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void saveOperateClassAuthSet(Map<String, Object> param) {
		String orgId = (String) param.get("orgId");
		String deptId = (String) param.get("deptId");
		String sysId = (String) param.get("sysId");
		String operateClassId = (String) param.get("operateClassId");
		Map<String, Object>[] nodeDatas = (Map<String, Object>[]) param.get("nodeDatas");

		// 根据操作权限分类ID删除已设置的权限
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM LANTOP_OPERATE_CLASS_ITEM T WHERE T.LANTOP_OPERATE_CLASS_ID = '");
		sbSql.append(operateClassId);
		sbSql.append("'");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
		// 保存权限
		Map<String, Object> map;
		for (int i = 0; i < nodeDatas.length; i++) {
			map = nodeDatas[i];
			map = (Map<String, Object>) map.get("attributes");
			LantopOperateClassItem lantopOperateClassItem = new LantopOperateClassItem();
			lantopOperateClassItem.setId(ComUtil.getId());
			lantopOperateClassItem.setOrgId(orgId);
			lantopOperateClassItem.setDeptId(deptId);
			lantopOperateClassItem.setSysId(sysId);
			lantopOperateClassItem.setLantopOperateClassId(operateClassId);
			lantopOperateClassItem.setFuncMenuId((String) map.get("PARENT_ID"));
			lantopOperateClassItem.setOperateCode((String) map.get("MCODE"));
			PojoUtil.setSysProperties(lantopOperateClassItem, OpType.insert);
			this.hibernateDao.save(lantopOperateClassItem);
			SysLogUtil.log(lantopOperateClassItem, null, OpType.insert, OpResult.success);
		}
	}

	@Override
	public List<Map<String, Object>> getLantopOperateClassList(String relTargetId) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT LOC.ID,LOC.OPERATE_CLASS_NAME ");
		sbSql.append("  FROM LANTOP_OPERATE_CLASS LOC ");
		sbSql.append(" WHERE INSTR('");
		sbSql.append(relTargetId);
		sbSql.append("', LOC.ID) < 1");
		List<Map<String, Object>> list = this.jdbcAvicit.queryForMap(sbSql.toString(), null);
		return list;
	}



	@Override
	public void getSetOperatreClass(Page<Map<String, Object>> page, String relTargetId) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT LOC.ID,LOC.OPERATE_CLASS_NAME ");
		sbSql.append("  FROM LANTOP_OPERATE_CLASS LOC ");
		sbSql.append(" WHERE INSTR('");
		sbSql.append(relTargetId);
		sbSql.append("', LOC.ID) > 0");
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public void delLantopUserAuthSetExtendByResourceId(String ids) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM LANTOP_USER_AUTH_SET_EXTEND T WHERE T.CBB_AUTH_RESOURCE_ID IN (");
		sbSql.append(ids);
		sbSql.append(")");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	@Override
	public int getLantopUserAuthSetExtendCount(String targetType, String targetId, String authServiceId, String code) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT ID ");
		sbSql.append("  FROM LANTOP_USER_AUTH_SET_EXTEND T ");
		sbSql.append(" WHERE T.TARGET_TYPE = '" + targetType + "'");
		sbSql.append("   AND T.TARGET_ID = '" + targetId + "'");
		sbSql.append("   AND T.AUTH_SERVICE_ID = '" + authServiceId + "'");
		sbSql.append("   AND T.DATA_AUTH IS NOT NULL");
		sbSql.append("   AND T.RES_CODE LIKE '" + code + "_%'");
		List<Map<String, Object>> list = this.jdbcAvicit.queryForMap(sbSql.toString(), null);
		if (null != list) {
			return list.size();
		}
		return 0;
	}

	@Override
	public List<TreeNode> getMenuTreeNode(String id) throws Exception {
		List<TreeNode> nodes = new ArrayList<TreeNode>();
		// 查询业务数据
		List<Map<String, Object>> childTreeList = this.getMenuByParentId(id);
		for (Map<String, Object> row : childTreeList) {
			String rid = (String) row.get("id");
			String rname = (String) row.get("menu_name");
			TreeNode node = new TreeNode();
			node.setId(rid);
			node.setText(rname);
			node.setAttributes(row);
			BigDecimal childCount2 = BigDecimal.valueOf(Long.valueOf(row.get("CHILD_COUNT") + ""));
			if (null != childCount2 && childCount2.longValue() > 0) {
				List<TreeNode> cnode = getMenuTreeNode(rid);
				node.getChildren().addAll(cnode);
				node.setState("open");
			} else {
				node.setState("open");
			}
			nodes.add(node);
		}
		return nodes;
	}

	@Override
	public List<Map<String, Object>> getMenuByParentId(String parentId) throws Exception {
		Assert.notNull(parentId, "参数不能为空！");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("with a as ( ");
		sbSql.append("SELECT T.MENU_NAME, T.ID, T.PARENT_ID ");
		sbSql.append("  FROM (SELECT SMT.NAME AS MENU_NAME, SM.ID, SM.PARENT_ID ");
		sbSql.append("          FROM SYS_MENU SM ");
		sbSql.append("         INNER JOIN SYS_MENU_TL SMT ");
		sbSql.append("            ON SM.ID = SMT.SYS_MENU_ID ");
		sbSql.append("         WHERE SMT.NAME NOT IN ");
		sbSql.append("               ('系统管理', '门户小页', '系统首页', '个人事务') ");
		sbSql.append("           AND SMT.SYS_LANGUAGE_CODE = 'zh_CN') T ");
		sbSql.append(" START WITH T.ID = '1' ");
		sbSql.append("CONNECT BY PRIOR T.ID = T.PARENT_ID ");
		sbSql.append(") ");
		sbSql.append("SELECT (SELECT COUNT(*) FROM a a2 ");
		sbSql.append("WHERE a2.parent_id = a1.id) child_count,a1.* ");
		sbSql.append("FROM a a1 ");
		sbSql.append("WHERE a1.parent_id =?");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString(), new Object[] {parentId});
		return list;
	}

	@Override
	public void saveFuncResourceConfig(List<CbbAuthResource> cbbAuthResources, Map<String, Object> parameter) throws Exception {
		String orgId = (String) parameter.get("orgId");
		String sysId = (String) parameter.get("sysId");
		String targetId = (String) parameter.get("targetId");
		String serviceId = (String) parameter.get("serviceId");
		String menuId = (String) parameter.get("menuId");
		// 保存前先删掉之前该角色、服务、菜单下的配置信息
		this.baseExtendAuthService.deleteCbbAuthResource(orgId, sysId, targetId, serviceId, menuId);
		for (int i = 0; i < cbbAuthResources.size(); i++) {
			this.baseExtendAuthService.insertCbbAuthResource(cbbAuthResources.get(i));
		}
	}

	@Override
	public int getLantopUserAuthSetExtendByResourceId(String cbbAuthResourceIds) {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("SELECT ID FROM LANTOP_USER_AUTH_SET_EXTEND WHERE CBB_AUTH_RESOURCE_ID IN (");
		sbSql.append(cbbAuthResourceIds);
		sbSql.append(")");
		List<Map<String, Object>> list = this.jdbcAvicit.queryForMap(sbSql.toString(), null);
		if (null != list) {
			return list.size();
		}
		return 0;
	}

	@Override
	public void delAuthSet(String orgId, String deptId, String sysId, String targetType, String targetId, String codes) throws Exception {
		String[] code = codes.split(",");
		for (int j = 0; j < code.length; j++) {
			// 删除操作权限、条件设置
			StringBuffer sbSql1 = new StringBuffer();
			sbSql1.append("DELETE FROM LANTOP_USER_AUTH_SET_EXTEND WHERE ORG_ID = '" + orgId + "' AND SYS_ID = '" + sysId + "' AND TARGET_TYPE = '" + targetType + "' AND TARGET_ID = '" + targetId + "' AND RES_CODE LIKE '" + code[j] + "%' ");
			this.jdbcAvicit.getJdbcTemplate().execute(sbSql1.toString());
			SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
			// 删除条目权限设置
			StringBuffer sbSql2 = new StringBuffer();
			sbSql2.append("DELETE FROM LANTOP_USER_AUTH_EXTEND_DATA WHERE ORG_ID = '" + orgId + "' AND SYS_ID = '" + sysId + "' AND TARGET_TYPE = '" + targetType + "' AND TARGET_ID = '" + targetId + "' AND RES_CODE = '" + code[j] + "'");
			this.jdbcAvicit.getJdbcTemplate().execute(sbSql2.toString());
			SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
			// 删除权限设置（复选框）
			this.baseExtendAuthService.delCbbAuthResource(orgId, deptId, sysId, targetType, targetId, code[j]);
		}
	}



	@Override
	public void getAllUser(Page<Map<String, Object>> page, String targetId, Map<String, Object> param) {
		StringBuffer sbSql = new StringBuffer();
		// 在查询角色时，要将角色为空的用户删选掉
		if (null != param.get("roleNameAlias") && !"".equals(param.get("roleNameAlias"))) {
			sbSql.append("SELECT * FROM (");
		}
		sbSql.append("SELECT SU.ID, ");
		sbSql.append("       SU.NAME, ");
		sbSql.append("       SU.NO, ");
		sbSql.append("       SU.LOGIN_NAME, ");
		sbSql.append("       SDV.DEPT_NAME, SPT.POSITION_NAME, ");
		sbSql.append("       (SELECT CONCAT_CLOB_F(SR.ROLE_NAME) ");
		sbSql.append("          FROM SYS_ROLE SR ");
		sbSql.append("         WHERE SR.ID IN (SELECT SUR.SYS_ROLE_ID ");
		sbSql.append("                           FROM SYS_USER_ROLE SUR ");
		sbSql.append("                          WHERE SU.ID = SUR.SYS_USER_ID)");
		// 角色
		if (null != param.get("roleNameAlias") && !"".equals(param.get("roleNameAlias"))) {
			sbSql.append(" AND SR.ROLE_NAME IN(");
			String roleNameAlias = (String) param.get("roleNameAlias");
			String[] roleList = roleNameAlias.split(",");
			for (int i = 0; i < roleList.length; i++) {
				sbSql.append("'" + roleList[i] + "'");
				if (i < roleList.length - 1) {
					sbSql.append(",");
				}
			}
			sbSql.append(")");
		}
		sbSql.append(") ROLE_NAME ");
		sbSql.append("  FROM SYS_USER SU ");
		sbSql.append(" INNER JOIN SYS_USER_DEPT_POSITION SUDP ");
		sbSql.append("    ON SU.ID = SUDP.USER_ID ");
		sbSql.append(" INNER JOIN SYS_DEPT_V SDV ");
		sbSql.append("    ON SDV.ID = SUDP.DEPT_ID ");
		sbSql.append(" INNER JOIN SYS_POSITION SP ");
		sbSql.append("	ON SUDP.POSITION_ID = SP.ID ");
		sbSql.append(" INNER JOIN SYS_POSITION_TL SPT ");
		sbSql.append(" ON SP.ID = SPT.SYS_POSITION_ID ");
		sbSql.append(" WHERE SU.ID != '" + targetId + "'");
		if (null != param.get("userName") && !"".equals(param.get("userName"))) {
			sbSql.append(" AND SU.NAME LIKE '%" + param.get("userName") + "%'");
		}
		if (null != param.get("userCode") && !"".equals(param.get("userCode"))) {
			sbSql.append(" AND SU.LOGIN_NAME LIKE '%" + param.get("userCode") + "%'");
		}
		// 岗位
		if (null != param.get("positionNameAlias") && !"".equals(param.get("positionNameAlias"))) {
			sbSql.append(" AND SPT.POSITION_NAME IN(");
			String positionNameAlias = (String) param.get("positionNameAlias");
			String[] positionList = positionNameAlias.split(",");
			for (int i = 0; i < positionList.length; i++) {
				sbSql.append("'" + positionList[i] + "'");
				if (i < positionList.length - 1) {
					sbSql.append(",");
				}
			}
			sbSql.append(")");
		}
		// 部门
		if (null != param.get("deptNameAlias") && !"".equals(param.get("deptNameAlias"))) {
			sbSql.append(" AND SDV.DEPT_NAME IN(");
			String deptNameAlias = (String) param.get("deptNameAlias");
			String[] deptList = deptNameAlias.split(",");
			for (int i = 0; i < deptList.length; i++) {
				sbSql.append("'" + deptList[i] + "'");
				if (i < deptList.length - 1) {
					sbSql.append(",");
				}
			}
			sbSql.append(")");
		}
		sbSql.append(" ORDER BY SDV.DEPT_NAME ");
		if (null != param.get("roleNameAlias") && !"".equals(param.get("roleNameAlias"))) {
			sbSql.append(" )RESULT WHERE RESULT.ROLE_NAME IS NOT NULL");
		}
		this.jdbcAvicit.getDatesByPageForMap(page, sbSql.toString(), null, null);
	}

	@Override
	public List<LantopUserAuthSetExtend> getLantopUserAuthSetExtend(String orgId, String deptId, String sysId, String targetId) {
		List<LantopUserAuthSetExtend> list = this.hibernateDao.find(" from LantopUserAuthSetExtend where orgId = ? and sysId = ? and targetId = ?", new Object[] {orgId, sysId, targetId});
		return list;
	}

	@Override
	public List<LantopUserAuthExtendData> getLantopUserAuthExtendData(String orgId, String deptId, String sysId, String targetId) {
		List<LantopUserAuthExtendData> list = this.hibernateDao.find(" from LantopUserAuthExtendData where orgId = ? and sysId = ? and targetId = ?", new Object[] {orgId, sysId, targetId});
		return list;
	}

	@Override
	public void saveCopyToTargetUser(String orgId, String deptId, String sysId, List<LantopUserAuthSetExtend> lantopUserAuthSetExtends, List<LantopUserAuthExtendData> lantopUserAuthExtendDatas, List<CbbAuthResource> cbbAuthResources, String targetUserIds) throws Exception {
		String[] targetUserId = targetUserIds.split(",");
		for (int i = 0; i < targetUserId.length; i++) {
			// 删除现有权限
			StringBuffer sbSql1 = new StringBuffer();
			sbSql1.append("DELETE FROM LANTOP_USER_AUTH_EXTEND_DATA WHERE TARGET_ID = '" + targetUserId[i] + "'");
			this.jdbcAvicit.getJdbcTemplate().execute(sbSql1.toString());
			SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
			// 删除现有权限
			StringBuffer sbSql2 = new StringBuffer();
			sbSql2.append("DELETE FROM LANTOP_USER_AUTH_SET_EXTEND WHERE TARGET_ID = '" + targetUserId[i] + "'");
			this.jdbcAvicit.getJdbcTemplate().execute(sbSql2.toString());
			SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
			this.baseExtendAuthService.delCbbAuthResource(orgId, deptId, sysId, targetUserId[i]);
		}

		for (int i = 0; i < lantopUserAuthSetExtends.size(); i++) {
			LantopUserAuthSetExtend lantopUserAuthSetExtend = lantopUserAuthSetExtends.get(i);
			PojoUtil.setSysProperties(lantopUserAuthSetExtend, OpType.insert);
			for (int j = 0; j < targetUserId.length; j++) {
				this.hibernateDao.evict(lantopUserAuthSetExtend);
				lantopUserAuthSetExtend.setId(ComUtil.getId());
				lantopUserAuthSetExtend.setTargetId(targetUserId[j]);
				this.hibernateDao.save(lantopUserAuthSetExtend);
				SysLogUtil.log(lantopUserAuthSetExtend, null, OpType.insert, OpResult.success);
			}
		}

		for (int i = 0; i < lantopUserAuthExtendDatas.size(); i++) {
			LantopUserAuthExtendData lantopUserAuthExtendData = lantopUserAuthExtendDatas.get(i);
			PojoUtil.setSysProperties(lantopUserAuthExtendData, OpType.insert);
			for (int j = 0; j < targetUserId.length; j++) {
				this.hibernateDao.evict(lantopUserAuthExtendData);
				lantopUserAuthExtendData.setId(ComUtil.getId());
				lantopUserAuthExtendData.setTargetId(targetUserId[j]);
				this.hibernateDao.save(lantopUserAuthExtendData);
				SysLogUtil.log(lantopUserAuthExtendData, null, OpType.insert, OpResult.success);
			}
		}
	}

	@Override
	public void saveCbbAuthResourceAndUpdateSetExtendByUserIds(String orgId, String deptId, String sysId, List<CbbAuthResource> cbbAuthResources, String targetUserIds) throws Exception {
		String[] targetUserId = targetUserIds.split(",");
		for (int i = 0; i < cbbAuthResources.size(); i++) {
			CbbAuthResource cbbAuthResource = cbbAuthResources.get(i);
			for (int j = 0; j < targetUserId.length; j++) {
				String cbbAuthResourceId = cbbAuthResource.getId(); // 复制前数据ID
				this.hibernateDao.evict(cbbAuthResource);
				cbbAuthResource.setTargetId(targetUserId[j]);
				this.baseExtendAuthService.insertCbbAuthResource(cbbAuthResource);
				// 更新复制关系为复制后的ID
				StringBuffer sbSql = new StringBuffer();
				sbSql.append("UPDATE LANTOP_USER_AUTH_SET_EXTEND SET CBB_AUTH_RESOURCE_ID = '" + cbbAuthResource.getId() + "' WHERE CBB_AUTH_RESOURCE_ID = '" + cbbAuthResourceId + "' AND TARGET_ID = '" + targetUserId[j] + "'");
				this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
				SysLogUtil.log("用户权限设置模块", "修改权限设置记录", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
			}
		}
	}

	@Override
	public void deleteAuthCopyDataByRollBack(String orgId, String deptId, String sysId, String targetUserIds) throws Exception {
		String[] targetUserId = targetUserIds.split(",");
		for (int i = 0; i < targetUserId.length; i++) {
			// 删除现有权限
			StringBuffer sbSql1 = new StringBuffer();
			sbSql1.append("DELETE FROM LANTOP_USER_AUTH_EXTEND_DATA WHERE TARGET_ID = '" + targetUserId[i] + "'");
			this.jdbcAvicit.getJdbcTemplate().execute(sbSql1.toString());
			SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
			// 删除现有权限
			StringBuffer sbSql2 = new StringBuffer();
			sbSql2.append("DELETE FROM LANTOP_USER_AUTH_SET_EXTEND WHERE TARGET_ID = '" + targetUserId[i] + "'");
			this.jdbcAvicit.getJdbcTemplate().execute(sbSql2.toString());
			SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
			this.baseExtendAuthService.delCbbAuthResource(orgId, deptId, sysId, targetUserId[i]);
		}
	}

	@Override
	public void saveLantopQualificationDetail(List<Map<String, Object>> list, Map<String, String> param) throws Exception {
		String cols = param.get("cols");
		String ysf = param.get("ysf");
		String ljgx = param.get("ljgx");

		for (int i = 1; i <= list.size(); i++) {
			int j = i;
			Map<String, Object> map = list.get(j - 1);
			String orderBy = map.get("ORDER_BY") + "";
			String zdVal = (String) map.get("zdVal");
			String ysfVal = (String) map.get("ysfVal");
			String val = (String) map.get("val");
			String ljgxVal = (String) map.get("ljgxVal");

			StringBuffer sb = new StringBuffer();
			sb.append("<tr id=\"" + i + "\" style=\"border: 0px;\">\n" + "  <td style=\"border: 0px;\">\n" + "    <input id=\"zkh" + i + "\" name=\"zkh" + i + "\" class=\"easyui-validatebox\" readonly=\"readonly\" style=\"width:50px;\" value=\"(\">\n" + "  </td>\n"
					+ "  <td style=\"border: 0px;\">\n" + "    <input id=\"zd" + i + "\" name=\"zd" + i + "\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:" + cols + ",editable:false\" value=\"" + zdVal + "\">" + "  </td>\n"
					+ "  <td style=\"border: 0px;\">\n" + "    <input id=\"ysf" + i + "\" name=\"ysf" + i + "\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:" + ysf + ",editable:false\" value=\"" + ysfVal + "\">" + "  </td>\n"
					+ "  <td style=\"border: 0px;\">\n" + "    <input id=\"val" + i + "\" name=\"val" + i + "\" type=\"text\" class=\"easyui-validatebox\" value=\"" + val + "\"/>\n" + "  </td>\n" + "  <td style=\"border: 0px;\">\n" + "    <input id=\"ykh" + i + "\" name=\"ykh"
					+ i + "\" class=\"easyui-validatebox\" readonly=\"readonly\" style=\"width:50px;\" value=\")\">\n" + "  </td>\n" + "  <td style=\"border: 0px;\">\n" + "    <input id=\"ljgx" + i + "\" name=\"ljgx" + i
					+ "\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:" + ljgx + ",editable:false\" value=\"" + ljgxVal + "\">" + "  </td>\n" + "  <td style=\"border: 0px; width:50px;\">\n"
					+ "    <a class=\"easyui-linkbutton\" plain=\"false\" iconCls=\"\" onclick=\"addtr('test');\"\n" + "        href=\"javascript:void(0);\" >+</a>\n" + "  </td>\n");
			if (i != 1) {
				// 第一行没有删除
				sb.append("  <td style=\"border: 0px; width:50px;\">\n" + "    <a class=\"easyui-linkbutton\" plain=\"false\" iconCls=\"\" onclick=\"deltr(this);\"\n" + "        href=\"javascript:void(0);\" >-</a>\n" + "  </td>\n");
			}
			sb.append("</tr>");
			// if(orderBy != "1"){
			// sb.append(
			// "<tr id=\""+orderBy+"\" style=\"border: 0px;\">\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"zkh"+orderBy+"\" name=\"zkh"+orderBy+"\" class=\"easyui-validatebox\" readonly=\"readonly\" style=\"width:50px;\" value=\"(\">\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"zd"+orderBy+"\" name=\"zd"+orderBy+"\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:"+cols+",editable:false\" >\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"ysf"+orderBy+"\" name=\"ysf"+orderBy+"\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:"+ysf+",editable:false\">\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"val"+orderBy+"\" name=\"val"+orderBy+"\" type=\"text\" class=\"easyui-validatebox\" onfocus=\"onValInput('"+orderBy+"')\" onblur=\"onValInputAffter('"+orderBy+"')\" />\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"ykh"+orderBy+"\" name=\"ykh"+orderBy+"\" class=\"easyui-validatebox\" readonly=\"readonly\" style=\"width:50px;\" value=\")\">\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"ljgx"+orderBy+"\" name=\"ljgx"+orderBy+"\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:"+ljgx+",editable:false\">\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px; width:50px;\">\n" +
			// "    <a class=\"easyui-linkbutton\" plain=\"false\" iconCls=\"\" onclick=\"addtr('test');\"\n"
			// +
			// "        href=\"javascript:void(0);\" >+</a>\n" +
			// "  </td>\n" +
			// "  <td style=\"border: 0px; width:50px;\">\n" +
			// "    <a class=\"easyui-linkbutton\" plain=\"false\" iconCls=\"\" onclick=\"deltr(this);\"\n"
			// +
			// "        href=\"javascript:void(0);\" >-</a>\n" +
			// "  </td>\n" +
			// "</tr>");
			// }
			// else {
			// sb.append(
			// "<tr id=\""+orderBy+"\" style=\"border: 0px;\">\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"zkh"+orderBy+"\" name=\"zkh"+orderBy+"\" class=\"easyui-validatebox\" readonly=\"readonly\" style=\"width:50px;\" value=\"(\">\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"zd"+orderBy+"\" name=\"zd"+orderBy+"\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:"+cols+",editable:false\" >\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"ysf"+orderBy+"\" name=\"ysf"+orderBy+"\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:"+ysf+",editable:false\">\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"val"+orderBy+"\" name=\"val"+orderBy+"\" type=\"text\" class=\"easyui-validatebox\" onfocus=\"onValInput('"+orderBy+"')\" onblur=\"onValInputAffter('"+orderBy+"')\" />\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"ykh"+orderBy+"\" name=\"ykh"+orderBy+"\" class=\"easyui-validatebox\" readonly=\"readonly\" style=\"width:50px;\" value=\")\">\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px;\">\n" +
			// "    <input id=\"ljgx"+orderBy+"\" name=\"ljgx"+orderBy+"\" class=\"easyui-combobox\" data-options=\"valueField: 'id',textField: 'text',data:"+ljgx+",editable:false\">\n"
			// +
			// "  </td>\n" +
			// "  <td style=\"border: 0px; width:50px;\">\n" +
			// "    <a class=\"easyui-linkbutton\" plain=\"false\" iconCls=\"\" onclick=\"addtr('test');\"\n"
			// +
			// "        href=\"javascript:void(0);\" >+</a>\n" +
			// "  </td>\n" +
			// "  <td style=\"border: 0px; width:50px;\"> \n" +
			// "  </td>\n" +
			// "</tr>");
			// }
			LantopQualificationDetail lantopQualificationDetail = new LantopQualificationDetail();
			lantopQualificationDetail.setId(ComUtil.getId());
			lantopQualificationDetail.setSysId(param.get("sysId"));
			lantopQualificationDetail.setOrgId(param.get("orgId"));
			lantopQualificationDetail.setDeptId(param.get("deptId"));
			PojoUtil.setSysProperties(lantopQualificationDetail, OpType.insert);
			lantopQualificationDetail.setZdm((String) map.get("ZDM")); // 字段名
			lantopQualificationDetail.setQualificationValue((String) map.get("QUALIFICATION_VALUE"));
			lantopQualificationDetail.setLogic((String) map.get("LOGIC"));
			lantopQualificationDetail.setQualificationHtml(sb.toString());
			lantopQualificationDetail.setOrderBy(Long.parseLong(orderBy));
			lantopQualificationDetail.setCbbAuthResourceId(param.get("cbbAuthResourceId"));
			this.hibernateDao.save(lantopQualificationDetail);
			SysLogUtil.log(lantopQualificationDetail, null, OpType.insert, OpResult.success);
		}
	}

	@Override
	public void delLantopQualificationDetail(String cbbAuthResourceId) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("DELETE FROM LANTOP_QUALIFICATION_DETAIL WHERE CBB_AUTH_RESOURCE_ID = '" + cbbAuthResourceId + "'");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "删除权限设置记录", OpType.delete, OpResult.success, LogBaseFactory.getLogBase());
	}

	@Override
	public List<LantopQualificationDetail> getLantopQualificationDetails(String cbbAuthResourceId) {
		String hql = " from LantopQualificationDetail where cbbAuthResourceId = ?";
		return this.hibernateDao.find(hql, new Object[] {cbbAuthResourceId});
	}

	@Override
	public void saveLantopQualifcicationDetail(LantopQualificationDetail lantopQualificationDetail) throws Exception {
		this.hibernateDao.evict(lantopQualificationDetail);
		lantopQualificationDetail.setId(ComUtil.getId());
		PojoUtil.setSysProperties(lantopQualificationDetail, OpType.insert);
		this.hibernateDao.save(lantopQualificationDetail);
		SysLogUtil.log(lantopQualificationDetail, null, OpType.insert, OpResult.success);
	}

	@Override
	public List<Map<String, Object>> getSysConfig(Map<String, Object> param) throws Exception {
		String configKeyCode = (String) param.get("CONFIG_KEY_CODE");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append(" SELECT * FROM LANTOP_SYS_CONFIG WHERE CONFIG_KEY_CODE = '" + configKeyCode + "'");
		return this.jdbcAvicit.queryForMap(sbSql.toString(), null);
	}

	@Override
	public void saveSysConfig(Map<String, Object> param) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append(" INSERT INTO LANTOP_SYS_CONFIG ");
		sbSql.append("   (ID, ");
		sbSql.append("   SYS_ID, ");
		sbSql.append("   DEPT_ID, ");
		sbSql.append("   ORG_ID, ");
		sbSql.append("   CONFIG_KEY_NAME, ");
		sbSql.append("   CONFIG_KEY_CODE, ");
		sbSql.append("   CONFIG_KEY_VALUE, ");
		sbSql.append("   CREATION_DATE, ");
		sbSql.append("   CREATED_BY, ");
		sbSql.append("   LAST_UPDATE_DATE, ");
		sbSql.append("   LAST_UPDATED_BY, ");
		sbSql.append("   LAST_UPDATE_IP, ");
		sbSql.append("   VERSION) ");
		sbSql.append(" VALUES (");
		sbSql.append("'" + (String) param.get("ID") + "'");
		sbSql.append(",'" + (String) param.get("SYS_ID") + "'");
		sbSql.append(",'" + (String) param.get("DEPT_ID") + "'");
		sbSql.append(",'" + (String) param.get("ORG_ID") + "'");
		sbSql.append(",'" + (String) param.get("CONFIG_KEY_NAME") + "'");
		sbSql.append(",'" + (String) param.get("CONFIG_KEY_CODE") + "'");
		sbSql.append(",'" + (String) param.get("CONFIG_KEY_VALUE") + "'");
		sbSql.append(",to_date('" + (String) param.get("CREATION_DATE") + "','yyyy-mm-dd')");
		sbSql.append(",'" + (String) param.get("CREATED_BY") + "'");
		sbSql.append(",to_date('" + (String) param.get("LAST_UPDATE_DATE") + "','yyyy-mm-dd')");
		sbSql.append(",'" + (String) param.get("LAST_UPDATED_BY") + "'");
		sbSql.append(",'" + (String) param.get("LAST_UPDATE_IP") + "'");
		sbSql.append(",0");
		sbSql.append(")");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "新增系统配置记录", OpType.insert, OpResult.success, LogBaseFactory.getLogBase());
	}

	@Override
	public void updateSysConfig(Map<String, Object> param) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append(" UPDATE LANTOP_SYS_CONFIG SET CONFIG_KEY_VALUE = '" + param.get("CONFIG_KEY_VALUE") + "', ATTRIBUTE_08 = '" + param.get("ATTRIBUTE_08") + "' WHERE ID = '" + param.get("ID") + "'");
		this.jdbcAvicit.getJdbcTemplate().execute(sbSql.toString());
		SysLogUtil.log("用户权限设置模块", "修改系统配置记录", OpType.update, OpResult.success, LogBaseFactory.getLogBase());
	}

	@Override
	public String getClassNodeType(String str) throws Exception {
		String nodeType = "";
		StringBuffer sbSql = new StringBuffer();
		sbSql.append(" SELECT T.ARCHIVE_CLASS_NODE_TYPE FROM LANTOP_ARCHIVE_CLASS T WHERE T.ID = '" + str + "'");
		List<Map<String, Object>> listn = this.jdbcAvicit.queryForMap(sbSql.toString(), null);
		if (null != listn && listn.size() != 0) {
			nodeType = String.valueOf(listn.get(0).get("ARCHIVE_CLASS_NODE_TYPE"));
		}
		return nodeType;
	}

	@Override
	public String getClassNodeIds(String orgId, String deptId, String sysId, String targetId) throws Exception {
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("select CODE  FROM CBB_AUTH_RESOURCE WHERE ORG_ID = '" + orgId + "' AND DEPT_ID = '" + deptId + "' AND SYS_ID = '" + sysId + "' AND TARGET_ID = '" + targetId + "'");
		List<Map<String, Object>> list = this.jdbcAvicit.queryForMap(sbSql.toString(), null);
		String nodeIds = "";
		for (int i = 0; i < list.size(); i++) {
			if ("".equals(nodeIds)) {
				nodeIds = nodeIds + list.get(i).get("CODE").toString();
			} else {
				nodeIds = nodeIds + "," + list.get(i).get("CODE").toString();
			}
		}
		return nodeIds;

	}

	@Override
	public List<Map<String, Object>> getUserAuthExtendDatasByNodeId(String nodeId) throws Exception {
		String sql = "SELECT T.* FROM LANTOP_USER_AUTH_EXTEND_DATA T WHERE T.ARCHIVE_CLASS_ID = '" + nodeId + "'";
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sql);
		return list;
	}



	@Override
	public void getUserRoleList(Page<Map<String, Object>> page, String name, String orgId) {
		StringBuffer sql = new StringBuffer("SELECT * FROM BPM_DEF_ROLE_V t ");
		sql.append(" WHERE t.ORG_IDENTITY ='" + orgId + "' ");
		if (name != null) {
			sql.append(" AND t.ROLE_NAME like '%" + name + "%'");
		}
		this.jdbcAvicit.getDatesByPageForMap(page, sql.toString(), null, null);
	}

	public List<Map<String, Object>> getUserAuthDatasByParam(Map<String, Object> param) throws Exception {
		String nodeId = (String) param.get("nodeId");
		String targetType = (String) param.get("targetType");
		String targetId = (String) param.get("targetId");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("select cart.* from cbb_auth_resource cart\n");
		sbSql.append("left join lantop_user_auth_set_extend luase on luase.cbb_auth_resource_id = cart.id\n");
		sbSql.append("where cart.code in (\n");
		sbSql.append("select c.id\n");
		sbSql.append("    from lantop_archive_class c\n");
		sbSql.append("   where instr(c.archive_class_node_path,\n");
		sbSql.append("               (select aa.archive_class_node_path from lantop_archive_class aa where id = '" + nodeId + "')) > 0\n");
		sbSql.append("     and c.id not in\n");
		sbSql.append("         (select lac.id\n");
		sbSql.append("            from lantop_archive_class lac\n");
		sbSql.append("          connect by prior lac.id = lac.parent_id\n");
		sbSql.append("           start with id in\n");
		sbSql.append("                      (select a.id\n");
		sbSql.append("                         from lantop_archive_class a\n");
		sbSql.append("                        where a.archive_class_node_code in ('GRWJ', 'BMWJ') OR a.archive_type = '10'))\n");
		sbSql.append(")\n");
		sbSql.append("and cart.target_type = '" + targetType + "' and cart.target_id = '" + targetId + "'\n");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		return list;
	}

	/***********************手动批量设置操作权限********************************/
	public List<Map<String, Object>> getUserAuthDatasByIdsParam(Map<String, Object> param) throws Exception {
		String targetType = (String) param.get("targetType");
		String targetId = (String) param.get("targetId");
		String id = (String) param.get("id");

		StringBuffer sbSql = new StringBuffer();
		sbSql.append("select cart.* from cbb_auth_resource cart\n");
		// sbSql.append("left join lantop_user_auth_set_extend luase on luase.cbb_auth_resource_id = cart.id\n");
		sbSql.append("where cart.code in (\n");

		sbSql.append("select t.id from lantop_archive_class t\n");
		sbSql.append("where t.id not in (\n");
		sbSql.append("    select tt.id from lantop_archive_class tt\n");
		sbSql.append("    connect by prior tt.id = tt.parent_id\n");
		sbSql.append("    start with tt.archive_class_node_code = 'BMWJ'\n");
		sbSql.append(") and t.id not in (\n");
		sbSql.append("     select tt.id from lantop_archive_class tt\n");
		sbSql.append("    connect by prior tt.id = tt.parent_id\n");
		sbSql.append("    start with tt.archive_class_node_code = 'GRWJ'\n");
		sbSql.append(") and t.archive_class_node_type = '2'\n");
		sbSql.append("connect by prior t.id = t.parent_id\n");
		sbSql.append("start with t.parent_id = '" + id + "'");

		sbSql.append(")\n");
		sbSql.append("and cart.target_type = '" + targetType + "' and cart.target_id = '" + targetId + "'\n");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		return list;
	}

	/***********************手动批量设置操作权限********************************/

	public List<Map<String, Object>> getCbbAuthResourceDatasByNodeId(Map<String, Object> param) throws Exception {
		String orgId = (String) param.get("orgId");
		String sysId = (String) param.get("sysId");
		String targetId = (String) param.get("targetId");
		String targetType = (String) param.get("targetType");
		String idsSql = (String) param.get("idsSql");
		StringBuffer sbSql = new StringBuffer();
		sbSql.append("select * from (\n");
		sbSql.append("select * from ( WITH CARU AS\n");
		sbSql.append(" (SELECT distinct (CART.ID),\n");
		sbSql.append("                  CART.AUTH_SERVICE_ID,\n");
		sbSql.append("                  CART.TARGET_TYPE,\n");
		sbSql.append("                  CART.TARGET_ID,\n");
		sbSql.append("                  CART.CODE,\n");
		sbSql.append("                  CART.NAME,\n");
		sbSql.append("                  CART.ACTION_TYPE,\n");
		sbSql.append("                  CART.OPERATE_AUTH,\n");
		sbSql.append("                  SUBSTR(CART.OPERATE_AUTH, 1, 1) AS A1,\n");
		sbSql.append("                  SUBSTR(CART.OPERATE_AUTH, 3, 1) AS A2,\n");
		sbSql.append("                  SUBSTR(CART.OPERATE_AUTH, 5, 1) AS A3,\n");
		sbSql.append("                  SUBSTR(CART.OPERATE_AUTH, 7, 1) AS A4,\n");
		sbSql.append("                  LUASE.REL_TARGET_ID,\n");
		sbSql.append("                  LUASE.REL_TARGET_NAME\n");
		sbSql.append("    FROM CBB_AUTH_RESOURCE CART\n");
		sbSql.append("    LEFT JOIN LANTOP_USER_AUTH_SET_EXTEND LUASE\n");
		sbSql.append("      ON CART.ID = LUASE.CBB_AUTH_RESOURCE_ID\n");
		sbSql.append("   WHERE CART.TARGET_TYPE = '" + targetType + "'\n");
		sbSql.append("     AND CART.ORG_ID = '" + orgId + "'\n");
		sbSql.append("     AND CART.SYS_ID = '" + sysId + "'\n");
		sbSql.append("     AND CART.AUTH_SERVICE_ID = 'LANTOP_AUTH_SERVER_USERSET'\n");
		sbSql.append("     AND CART.TARGET_ID = '" + targetId + "')\n");
		sbSql.append("SELECT LAC.ORG_ID,\n");
		sbSql.append("       LAC.DEPT_ID,\n");
		sbSql.append("       LAC.SYS_ID,\n");
		sbSql.append("       LAC.ARCHIVE_CLASS_NODE_NAME,\n");
		sbSql.append("       LAC.ARCHIVE_CLASS_NODE_TYPE,\n");
		sbSql.append("       LAC.ID,\n");
		sbSql.append("       LAC.PARENT_ID,\n");
		sbSql.append("       LAC.NODE_SORT_NUMBER,\n");
		sbSql.append("       LAC.CREATION_DATE,\n");
		sbSql.append("       CARU.ID AS CBB_AUTH_RESOURCE_ID,\n");
		sbSql.append("       CARU.AUTH_SERVICE_ID,\n");
		sbSql.append("       CARU.TARGET_TYPE,\n");
		sbSql.append("       CARU.TARGET_ID,\n");
		sbSql.append("       CARU.CODE AS RES_CODE,\n");
		sbSql.append("       CARU.NAME AS RES_NAME,\n");
		sbSql.append("       CARU.ACTION_TYPE,\n");
		sbSql.append("       CARU.OPERATE_AUTH,\n");
		sbSql.append("       LAC.ARCHIVE_TYPE,\n");
		sbSql.append("       CASE\n");
		sbSql.append("         WHEN CARU.A1 IS NULL THEN\n");
		sbSql.append("          'A10'\n");
		sbSql.append("         ELSE\n");
		sbSql.append("          'A1' || CARU.A1\n");
		sbSql.append("       END A1,\n");
		sbSql.append("       CASE\n");
		sbSql.append("         WHEN CARU.A2 IS NULL THEN\n");
		sbSql.append("          'A20'\n");
		sbSql.append("         ELSE\n");
		sbSql.append("          'A2' || CARU.A2\n");
		sbSql.append("       END A2,\n");
		sbSql.append("       CASE\n");
		sbSql.append("         WHEN CARU.A3 IS NULL THEN\n");
		sbSql.append("          'A30'\n");
		sbSql.append("         ELSE\n");
		sbSql.append("          'A3' || CARU.A3\n");
		sbSql.append("       END A3,\n");
		sbSql.append("       CASE\n");
		sbSql.append("         WHEN CARU.A4 IS NULL THEN\n");
		sbSql.append("          'A40'\n");
		sbSql.append("         ELSE\n");
		sbSql.append("          'A4' || CARU.A4\n");
		sbSql.append("       END A4,\n");
		sbSql.append("       CARU.REL_TARGET_ID,\n");
		sbSql.append("       CARU.REL_TARGET_NAME\n");
		sbSql.append("  FROM LANTOP_ARCHIVE_CLASS LAC\n");
		sbSql.append("  LEFT JOIN CARU\n");
		sbSql.append("    ON LAC.ID = CARU.CODE\n");
		sbSql.append(" WHERE LAC.ORG_ID = '" + orgId + "'\n");
		sbSql.append("   AND LAC.SYS_ID = '" + sysId + "'\n");
		sbSql.append("   AND LAC.ARCHIVE_CLASS_NODE_CODE NOT IN ('BMWJ', 'GRWJ')\n");
		sbSql.append("   AND LAC.ID NOT IN (SELECT T.ID\n");
		sbSql.append("                        FROM LANTOP_ARCHIVE_CLASS T\n");
		sbSql.append("                       START WITH T.ARCHIVE_TYPE = '10'\n");
		sbSql.append("                      CONNECT BY PRIOR T.PARENT_ID = T.ID\n");
		sbSql.append("                             AND PARENT_ID != 'ROOT')\n");
		sbSql.append(" ORDER BY LAC.NODE_SORT_NUMBER, LAC.CREATION_DATE\n");
		sbSql.append(") AA\n");
		sbSql.append("CONNECT BY PRIOR AA.ID = AA.PARENT_ID\n");
		sbSql.append("START WITH AA.ID IN (" + idsSql + ")\n");
		sbSql.append("ORDER SIBLINGS BY NODE_SORT_NUMBER,CREATION_DATE) AAA\n");
		sbSql.append("WHERE AAA.ARCHIVE_CLASS_NODE_TYPE = '2' AND AAA.A1 = 'A11'");
		List<Map<String, Object>> list = this.jdbcAvicit.getJdbcTemplate().queryForList(sbSql.toString());
		return list;
	}


	/**
	 * 根据名称获得用户信息（登录名或者姓名）
	 * @param page  分页
	 * @param name  登录名或者姓名
	 * @param orgId  组织应用ID
	 * @param deptId   部门ID 
	 * 
	 * */

	public void getUsers(Page<Map<String, Object>> page, String name, String orgId, String deptId) {
		StringBuffer sql = new StringBuffer("SELECT * FROM LANTOP_USER_V t ");
		sql.append(" WHERE t.ORG_IDENTITY ='" + orgId + "' ");
		if (name != null && !name.equals("")) {
			sql.append(" AND (t.NAME like '%" + name + "%'");
			sql.append(" OR t.LOGIN_NAME like '%" + name + "%')");
		}
		if (null != deptId && !deptId.equals("")) {
			sql.append(" AND t.dept_id = '" + deptId + "'");
		}
		this.jdbcAvicit.getDatesByPageForMap(page, sql.toString(), null, null);
	}

}
